package com.atguigu.cloud.resp;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum ReturnCodeEnum {
    RC200("200","操作成功"),
    RC400("400","前端错误"),
    RC500("500","后端错误");
    private final  String code;
    private final String message;
    ReturnCodeEnum(String code,String message){
        this.code=code;
        this.message=message;
    }
//    遍历
//    传统版本
    public static ReturnCodeEnum getReturnCodeEnum(String code){
        for (ReturnCodeEnum item : ReturnCodeEnum.values()) {
            if (item.getCode().equals(code)){
                return item;
            }
        }
        return null;
    }
//    Stream版本
    public static ReturnCodeEnum getReturnCodeEnumV2(String code){
        return Arrays.stream(ReturnCodeEnum.values()).filter( x -> x.getCode().equals(code)).findFirst().orElse(null);
    }

//    public static void main(String[] args) {
//        System.out.println(getReturnCodeEnum("200"));
//        System.out.println(getReturnCodeEnum("200").getCode());
//        System.out.println(getReturnCodeEnum("200").getMessage());
//    }

}
